package com.yicong.ants.view.popup;

import android.app.Activity;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.NonNull;

import com.cchao.simplelib.LibCore;
import com.cchao.simplelib.core.AndroidHelper;
import com.yicong.ants.R;
import com.yicong.ants.manager.BusinessHelper;
import com.yicong.ants.manager.CopyHelper;
import com.yicong.ants.manager.business.Dialogs;

import razerdp.basepopup.BasePopupWindow;


/**
 * @author cch
 * @version 2021/6/2
 */
public class CommonSharePopup extends BasePopupWindow implements View.OnClickListener {
    String mTitle;
    String mLink;

    public CommonSharePopup(Context context) {
        super(context);
        setContentView(R.layout.common_share_popup);
    }

    @Override
    public void onViewCreated(@NonNull View contentView) {
        super.onViewCreated(contentView);
        contentView.findViewById(R.id.share_wx).setOnClickListener(this);
        contentView.findViewById(R.id.ant_link).setOnClickListener(this);
        contentView.findViewById(R.id.share_qr).setOnClickListener(this);
    }

    public CommonSharePopup setTitle(String title, String link) {
        mTitle = title;
        mLink = link;
        return this;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.share_wx:
                BusinessHelper.shareAntLink((Activity) v.getContext(), mTitle, mLink);
                break;
            case R.id.ant_link:
                String shareLink = "【复制内容，打开蚁丛旅游App即可查看】\n" + mTitle + '\n' + mLink;
                AndroidHelper.setClipboardData(shareLink, () -> {
                    Toast toast = Toast.makeText(LibCore.getContext(), "链接内容已复制", Toast.LENGTH_SHORT);
                    toast.setGravity(Gravity.CENTER, 0, 0);
                    toast.show();
                });
                break;
            case R.id.share_qr:
                Dialogs.showQrContent((Activity) v.getContext(), mTitle, mLink);
                break;
        }
        dismiss();
    }
}
